import { message } from "antd";
import { find } from "lodash";
//参数配置
const checkOrderConfig = {
	//审核订单
	vertifyOrder: {
		vertValue: [{ key: "state", value: 10 }],
		noDataMsg: "勾选的订单无待审核订单"
	},
	//返审核订单
	reVertifyOrder: {
		vertValue: [{ key: "state", value: 20 }],
		noDataMsg: "勾选的订单无待发货订单"
	},
	//作废订单
	voidOrder: {
		vertValue: [
			{ key: "state", value: 10 },
			{ key: "state", value: 20 },
			{ key: "state", value: 30 }
		],
		noDataMsg: "已发货、已作废、被拆分、被合并的订单无法作废"
	},
	//取消作废订单
	cancelVoidOrder: {
		vertValue: [{ key: "state", value: 50 }],
		noDataMsg: "您勾选的订单不含有已作废订单，无法取消作废"
	},
	//转异常订单
	abnormalOrder: {
		vertValue: [
			{ key: "state", value: 10 },
			{ key: "state", value: 20 },
			{ key: "state", value: 30 }
		],
		noDataMsg: "已发货、已作废、被拆分、被合并的订单不能转异常"
	},
	//转正常订单
	normalOrder: {
		vertValue: [{ key: "state", value: 30 }],
		noDataMsg: "当前勾选订单不含有异常订单，无法转正常单"
	},
	//物流回传
	logisticReturn: {
		vertValue: [
			{ key: "state", value: 10 },
			{ key: "state", value: 20 },
			{ key: "state", value: 30 },
			{ key: "state", value: 40 }
		]
	},
	//按策略拆单
	autoSplitOrder: {
		vertValue: [{ key: "state", value: 10 }],
		noDataMsg: "已勾选订单中不含有待审核订单，无法执行此策略"
	},
	//修改商品
	modifyGoods: {
		vertValue: [
            { key: "state", value: 10 },
			{ key: "state", value: 30 }
		],
		noDataMsg: "已发货、已作废、被拆分、被合并的订单无法修改商品"
	},
	//修改快递
	modifyExpress: {
		vertValue: [
			{ key: "state", value: 10 },
			{ key: "state", value: 30 },
			{ key: "state", value: 20 }
		],
		noDataMsg: "无待审核、异常或待发货的订单，无法修改快递"
	},
	//批量输入运单号
	batchInputLogisticNo: {
		vertValue: [
			{ key: "state", value: 10 },
			{ key: "state", value: 30 },
			{ key: "state", value: 20 }
		],
		noDataMsg: "请勾选待审核、异常或待发货的订单"
	},
    //供应商匹配
	SupplierMatchingModal: {
		vertValue: [{ key: "state", value: 10 }, { key: "state", value: 30 }],
		noDataMsg: "未含有待审核和异常状态的订单，不能操作供应商匹配"
	},
};

//校验符合条件的订单数量
export const countOrderSum = (scene, selectKeys, orderList) => {
	const { vertValue } = checkOrderConfig[scene];
	const count = [];
	for (let j in vertValue) {
		count[j] = 0;
		for (let i in selectKeys) {
			const obj = find(orderList, ["id", selectKeys[i]]);
			if (obj) {
				if (obj[vertValue[j].key] == vertValue[j].value) {
					count[j] = count[j] + 1;
				}
			}
		}
	}
	if (count.length > 1) {
		return count;
	}
	return count[0];
};

//校验是否存在符合要求的订单
export const checkOrder = (scene, selectKeys, orderList) => {
	const { vertValue, noDataMsg } = checkOrderConfig[scene];
	for (let i in selectKeys) {
		const obj = find(orderList, ["id", selectKeys[i]]);
		if (obj) {
			for (let j in vertValue) {
				if (obj[vertValue[j].key] == vertValue[j].value) {
					return true;
				}
			}
		}
	}
	message.info(noDataMsg);
	return false;
};
